package com.jbl.te.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jbl.te.entity.Department;
import com.jbl.te.entity.Major;
import com.jbl.te.entity.vo.DepartmentQuery;
import com.jbl.te.entity.vo.MajorQuery;
import com.jbl.te.mapper.MajorMapper;
import com.jbl.te.service.MajorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jbl
 * @since 2020-12-11
 */
@Service
public class MajorServiceImpl extends ServiceImpl<MajorMapper, Major> implements MajorService {

    @Override
    public void pageQuery(Page<Major> pageParam, MajorQuery majorQuery) {
        if (majorQuery == null) {
            this.page(pageParam,null);
            return;
        }
        String name = majorQuery.getName();
        String collegeId = majorQuery.getCollegeId();
        String departmentId=majorQuery.getDepartmentId();
        QueryWrapper<Major> wrapper = new QueryWrapper<>();

        if(!StringUtils.isEmpty(name)) {
            wrapper.like("name",name);
        }
        if(!StringUtils.isEmpty(collegeId)) {
            wrapper.eq("college_id",collegeId);
        }
        if(!StringUtils.isEmpty(departmentId)) {
            wrapper.eq("department_id",departmentId);
        }

        this.page(pageParam,wrapper);
    }
}
